<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Bash Script gen_pack.sh</title>
<title>CMSIS-Pack: Bash Script gen_pack.sh</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 46px;">
  <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMSIS-Pack
   &#160;<span id="projectnumber">Version 1.6.1</span>
   </div>
   <div id="projectbrief">Delivery Mechanism for Software Packs</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
    <ul class="tablist">
      <script type="text/javascript">
		<!--
		writeComponentTabs.call(this);
		//-->
      </script>
	  </ul>
</div>
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('bash_script.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Bash Script gen_pack.sh </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The following <a href="https://en.wikipedia.org/wiki/Bash_(Unix_shell)" target="_blank">Bash</a> shell script template <a class="el" href="bash_script.html#gen_pack_sh">gen_pack.sh</a> allows you to generate a Pack file on the Linux or the Windows operating system. Bash is available for Windows, for example, via <a href="https://gitforwindows.org/" target="_blank">git for Windows</a>.</p>
<p>For using <a class="el" href="bash_script.html#gen_pack_sh">gen_pack.sh</a></p><ul>
<li>Install <a class="el" href="cp_ZIPTool.html">7-Zip</a> (and for Linux <a class="el" href="cp_Editors.html#xmllint">xmllint</a> for schema validation).</li>
<li>Adapt the file <a class="el" href="bash_script.html#gen_pack_sh">gen_pack.sh</a> that is available in the directory <b>/CMSIS/Pack/Bash</b> to the requirements of your software pack.</li>
</ul>
<p>The script is generic enough to cope with a wide range of requirements. It uses the information from the <a class="el" href="packFormat.html">*.PDSC file</a> to generate the output filename according the CMSIS-Pack conventions and validates the pack consistency with <a class="el" href="packChk.html">packChk</a>.</p>
<p>Below is a sample output (reduced). </p><div class="fragment"><div class="line">$ ./gen_pack.sh</div>
<div class="line"> </div>
<div class="line">Starting CMSIS-Pack Generation: 19 Aug 2019 15:34:02</div>
<div class="line">7z is /C/Program Files/7-Zip/7z</div>
<div class="line">PackChk is /C/Keil_v5/ARM/PACK/ARM/CMSIS/5.6.0/CMSIS/Utilities/Win32/PackChk</div>
<div class="line"> </div>
<div class="line">Generating Pack Version: <span class="keywordflow">for</span> MyVendor.MyPack</div>
<div class="line"> </div>
<div class="line">Adding directories to pack:</div>
<div class="line">Include/ Source/</div>
<div class="line"> </div>
<div class="line">Adding files to pack:</div>
<div class="line">License.txt ReadMe.txt</div>
<div class="line"> </div>
<div class="line">PackChk.exe 1.3.87</div>
<div class="line">Copyright (C) 2012-2019 ARM Ltd and ARM Germany GmbH. All rights reserved.</div>
<div class="line"> </div>
<div class="line">M362: Also suppressing Messages M502 and M504</div>
<div class="line"> </div>
<div class="line">Phase1: Read PDSC files</div>
<div class="line">Phase2: Static Data &amp; Dependencies check</div>
<div class="line">    WARNING M304: C:\W\CMSIS_5\CMSIS\Pack\Bash\build\MyVendor.MyPack.pdsc</div>
<div class="line">  No <span class="keyword">package </span>URL (&lt;url&gt;-tag and/or value) found in PDSC file!</div>
<div class="line"> </div>
<div class="line">Phase3: RTE Model based Data &amp; Dependencies check</div>
<div class="line">Found 0 Error(s) and 1 Warning(s).</div>
<div class="line"> </div>
<div class="line">creating pack file MyVendor.MyPack.1.0.0.pack</div>
<div class="line"> </div>
<div class="line">Creating archive: C:/W/CMSIS_5/CMSIS/Pack/Bash/output/MyVendor.MyPack.1.0.0.pack</div>
<div class="line">Add new data to archive: 2 folders, 5 files, 1165 bytes (2 KiB)</div>
<div class="line"> </div>
<div class="line">Everything is Ok</div>
<div class="line">Completed CMSIS-Pack Generation ...</div>
</div><!-- fragment --><p><a class="anchor" id="gen_pack_sh"></a><b>gen_pack.sh Bash script template file</b></p>
<p>The <b>gen_pack.sh</b> script template allows to configure:</p><ul>
<li>Path environment variables for related utilities</li>
<li>Directory names for temporary build and output files</li>
<li>Directory names and files in the root directory that should be included in the pack</li>
</ul>
<pre class="fragment">#!/bin/bash
# Version: 1.0 
# Date: 2019-08-16
# This bash script generates a CMSIS Software Pack:
#
# Pre-requisites:
# - bash shell (for Windows: install git for Windows)
# - 7z in path (zip archiving utility)
#   e.g. Ubuntu: sudo apt-get install p7zip-full p7zip-rar) 
# - PackChk in path with execute permission
#   (see CMSIS-Pack: CMSIS/Utilities/&lt;os&gt;/PackChk)
# - xmllint in path (XML schema validation; available only for Linux)

############### EDIT BELOW ###############
# Extend Path environment variable locally
#
if [ `uname -s` = "Linux" ]
  then
  CMSIS_PACK_PATH="/home/$USER/.arm/Packs/ARM/CMSIS/5.6.0/"
  PATH_TO_ADD="$CMSIS_PACK_PATH/CMSIS/Utilities/Linux-gcc-4.8.3/"
else
  CMSIS_PACK_PATH="/C/Keil_v5/ARM/PACK/ARM/CMSIS/5.6.0"
  PATH_TO_ADD="/C/Program Files/7-Zip/:$CMSIS_PACK_PATH/CMSIS/Utilities/Win32/"
fi
[[ ":$PATH:" != *":$PATH_TO_ADD}:"* ]] &amp;&amp; PATH="${PATH}:${PATH_TO_ADD}"
echo $PATH_TO_ADD appended to PATH
echo " "

# Pack warehouse directory - destination 
PACK_WAREHOUSE=output/

# Temporary pack build directory
PACK_BUILD=build/

# Specify directories included in pack relative to base directory
# All directories:
PACK_DIRS=`ls -d */`
# Do not include the build directory if it is local
PACK_DIRS=${PACK_DIRS//$PACK_BUILD/}
PACK_DIRS=${PACK_DIRS//$PACK_WAREHOUSE/}

# alternative: specify directory names to be added to pack base directory
# PACK_DIRS="
#  Source
#  Include
#"
  
# Specify file names to be added to pack base directory
PACK_BASE_FILES="
  License.txt
  ReadMe.txt
"

############ DO NOT EDIT BELOW ###########
echo Starting CMSIS-Pack Generation: `date`
# Zip utility check 
ZIP=7z
type -a $ZIP
errorlevel=$?
if [ $errorlevel -gt 0 ]
  then
  echo "Error: No 7zip Utility found"
  echo "Action: Add 7zip to your path"
  echo " "
  exit
fi

# Pack checking utility check
PACKCHK=PackChk
type -a $PACKCHK
errorlevel=$?
if [ $errorlevel != 0 ]
  then
  echo "Error: No PackChk Utility found"
  echo "Action: Add PackChk to your path"
  echo "Hint: Included in CMSIS Pack:"
  echo "&lt;pack_root_dir&gt;/ARM/CMSIS/&lt;version&gt;/CMSIS/Utilities/&lt;os&gt;/"
  echo " "
  exit
fi
echo " "

# Locate Package Description file
# check whether there is more than one pdsc file
NUM_PDSCS=`ls -1 *.pdsc | wc -l`
PACK_DESCRIPTION_FILE=`ls *.pdsc`
if [ $NUM_PDSCS -lt 1 ]
  then
  echo "Error: No *.pdsc file found in current directory"
  echo " "
elif [ $NUM_PDSCS -gt 1 ]
  then
  echo "Error: Only one PDSC file allowed in directory structure:"
  echo "Found:"
  echo "$PACK_DESCRIPTION_FILE"
  echo "Action: Delete unused pdsc files"
  echo " "
  exit
fi

SAVEIFS=$IFS
IFS=.
set $PACK_DESCRIPTION_FILE
# Pack Vendor
PACK_VENDOR=$1
# Pack Name
PACK_NAME=$2
echo Generating Pack Version: for $PACK_VENDOR.$PACK_NAME
echo " "
IFS=$SAVEIFS

#if $PACK_BUILD directory does not exist, create it.
if [ ! -d $PACK_BUILD ]; then
  mkdir -p $PACK_BUILD
fi

# Copy files into build base directory: $PACK_BUILD
# pdsc file is mandatory in base directory:
cp -f  ./$PACK_VENDOR.$PACK_NAME.pdsc ${PACK_BUILD}

# directories
echo Adding directories to pack:
echo $PACK_DIRS
echo " "
for d in ${PACK_DIRS}
do
  cp -r "$d" ${PACK_BUILD}
done

# files for base directory
echo Adding files to pack:
echo $PACK_BASE_FILES
echo " "
for f in $PACK_BASE_FILES
do 
  cp -f  "$f" $PACK_BUILD/ 
done

# Run Schema Check (for Linux only):
# sudo apt-get install libxml2-utils

if [ `uname -s` = "Linux" ]
  then
  echo Running schema check for $PACK_VENDOR.$PACK_NAME.pdsc
  xmllint --noout --schema ${CMSIS_PACK_PATH}/CMSIS/Utilities/PACK.xsd $PACK_BUILD/$PACK_VENDOR.$PACK_NAME.pdsc
  errorlevel=$?
  if [ $errorlevel -ne 0 ]; then
    echo "build aborted: Schema check of $PACK_VENDOR.$PACK_NAME.pdsc against PACK.xsd failed"
    echo " "
    exit
  fi
else
  echo "Use MDK PackInstaller to run schema validation for $PACK_VENDOR.$PACK_NAME.pdsc"
fi

# Run Pack Check and generate PackName file with version
$PACKCHK $PACK_BUILD/$PACK_VENDOR.$PACK_NAME.pdsc -n PackName.txt -x M362
errorlevel=$?
if [ $errorlevel -ne 0 ]; then
  echo "build aborted: pack check failed"
  echo " "
  exit
fi

PACKNAME=`cat PackName.txt`
rm -rf PackName.txt

# Archiving
# $ZIP a $PACKNAME
echo creating pack file $PACKNAME
#if $PACK_WAREHOUSE directory does not exist create it
if [ ! -d $PACK_WAREHOUSE ]; then
  mkdir -p $PACK_WAREHOUSE
fi
pushd $PACK_WAREHOUSE
PACK_WAREHOUSE=`pwd`
popd
pushd $PACK_BUILD
"$ZIP" a $PACK_WAREHOUSE/$PACKNAME -tzip
popd
errorlevel=$?
if [ $errorlevel -ne 0 ]; then
  echo "build aborted: archiving failed"
  exit
fi

echo "build of pack succeeded"
# Clean up
echo "cleaning up ..."

rm -rf $PACK_BUILD
echo " "

echo Completed CMSIS-Pack Generation: `date`
</pre> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="createPackUtil.html">Utilities for Creating Packs</a></li>
    <li class="footer">Generated on Tue Mar 17 2020 15:01:28 for CMSIS-Pack Version 1.6.1 by Arm Ltd. All rights reserved.
	<!--
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 
	-->
	</li>
  </ul>
</div>
</body>
</html>
